/**
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/index/login'),
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/index/register'),
    hidden: true,
  },
  {
    path: '/forget-password',
    component: () => import('@/views/index/forgetPassword'),
    hidden: true,
  },
  {
    path: '/apply',
    component: () => import('@/views/index/apply'),
    hidden: true,
  },
  {
    path: '/apply-success',
    component: () => import('@/views/index/applySuccess'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    hidden: true,
    redirect: 'home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/index/home'),
        meta: {
          title: '首页',
          icon: 'home',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/course-management',
    component: Layout,
    redirect: 'noRedirect',
    name: 'course-management',
    meta: {
      title: '排课管理',
      icon: 'book',
      permissions: ['leader', 'eduadmin'],
    },
    children: [
      {
        path: 'calendar',
        name: 'calendar',
        component: () => import('@/views/courseManagement/calendar'),
        meta: { title: '课程日历' },
      },
      {
        path: 'course-list',
        name: 'course-list',
        component: () => import('@/views/courseManagement/index'),
        meta: { title: '课程列表' },
      },
    ],
  },
  {
    path: '/resource',
    component: Layout,
    redirect: 'noRedirect',
    name: 'resource',
    meta: {
      title: '基础资源',
      icon: 'chalkboard-teacher',
      permissions: ['leader', 'eduadmin'],
    },
    children: [
      {
        path: 'teacher-list',
        name: 'teacher-list',
        component: () => import('@/views/teacherList'),
        meta: { title: '教师管理', icon: 'users-cog' },
      },
      {
        path: 'class-list',
        name: 'class-list',
        component: () => import('@/views/classList'),
        meta: { title: '班级管理', icon: 'users-cog' },
      },
      {
        path: 'student-list',
        name: 'student-list',
        component: () => import('@/views/studentList'),
        meta: { title: '学生管理', icon: 'users-cog' },
      },
      {
        path: 'classroom-list',
        name: 'classroom-list',
        component: () => import('@/views/classroomList'),
        meta: { title: '教室管理', icon: 'users-cog' },
      },
    ],
  },
  {
    path: '/system',
    component: Layout,
    redirect: 'noRedirect',
    name: 'system',
    meta: { title: '系统管理', icon: 'users-cog', permissions: ['leader'] },
    children: [
      {
        path: 'update-organ',
        name: 'update-organ',
        component: () => import('@/views/systemManagement/setting/updateOrgan'),
        meta: { title: '机构设置' },
      },
      {
        path: 'update-userinfo',
        name: 'update-userinfo',
        component: () =>
          import('@/views/systemManagement/setting/updateUserInfo'),
        meta: { title: '帐号设置' },
      },
      {
        path: 'update-password',
        name: 'update-password',
        component: () =>
          import('@/views/systemManagement/setting/updatePassword'),
        meta: { title: '重置密码' },
      },
      {
        path: 'user-list',
        name: 'user-list',
        component: () => import('@/views/systemManagement/user/index'),
        meta: { title: '人员管理' },
      },
    ],
  },
  {
    path: '/error',
    component: EmptyLayout,
    redirect: 'noRedirect',
    hidden: true,
    name: 'Error',
    meta: { title: 'error' },
    children: [
      {
        path: '401',
        name: 'Error401',
        component: () => import('@/views/401'),
        meta: { title: '401' },
      },
      {
        path: '404',
        name: 'Error404',
        component: () => import('@/views/404'),
        meta: { title: '404' },
      },
    ],
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export function resetRouter() {
  location.reload()
}

export default router
